package com.zxp.pstationapk.view;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.blankj.utilcode.util.ActivityUtils;
import com.blankj.utilcode.util.StringUtils;
import com.blankj.utilcode.util.Utils;
import com.zxp.pstationapk.R;
import com.zxp.pstationapk.util.GH;
import com.zxp.pstationapk.util.SpUtils;

import butterknife.BindView;
import butterknife.ButterKnife;

public class LoginActivity extends AppCompatActivity {
    @BindView(R.id.et_user)
    EditText et_user_input;
    @BindView(R.id.et_pwd)
    EditText et_pwd_input;
    @BindView(R.id.btn_login)
    Button btn_login;

    boolean firstLoginFlag = false;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
        ButterKnife.bind(this);
        initView();
        GH.init(this);
    }

    private void initView() {

        btn_login.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                 String userName = et_user_input.getText().toString().trim();
                 String pwd = et_pwd_input.getText().toString().trim();

                if (!StringUtils.isEmpty(userName) && !StringUtils.isEmpty(pwd)) {
                    if (userName.equals("admin") && pwd.equals("3802827@glg")) {
                        firstLoginFlag = true;
                        SpUtils.put(LoginActivity.this, "loginFlag", firstLoginFlag);
                        ActivityUtils.startActivity(MainActivity.class);
                        finish();
                    } else {
                        Toast.makeText(LoginActivity.this, R.string.tv_toast_2, Toast.LENGTH_SHORT).show();
                    }
                } else {
                    Toast.makeText(LoginActivity.this, R.string.tv_toast_1, Toast.LENGTH_SHORT).show();
                }
            }
        });
    }
}
